package com.future.mayi.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.dialog.SoldChangeDialog;
import com.future.mayi.model.AddressModel;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 寄卖订单
 */
public class SoldOrderActivity extends BaseTitleActivity {
    @BindView(R.id.tv_express_company)
    TextView tvExpressCompany;
    @BindView(R.id.tv_express_find)
    TextView tvExpressFind;
    @BindView(R.id.tv_express_code)
    TextView tvExpressCode;
    @BindView(R.id.ll_express)
    LinearLayout llExpress;
    @BindView(R.id.title_view_line)
    View titleViewLine;
    @BindView(R.id.tv_sub_title)
    TextView tvSubTitle;
    @BindView(R.id.ll_goods)
    LinearLayout llGoods;
    @BindView(R.id.tv_jijian_name)
    TextView tvJijianName;
    @BindView(R.id.tv_jijian_phone)
    TextView tvJijianPhone;
    @BindView(R.id.tv_jijian_address)
    TextView tvJijianAddress;
    @BindView(R.id.ll_server)
    LinearLayout llServer;
    @BindView(R.id.tv_order_code)
    TextView tvOrderCode;
    @BindView(R.id.ll_order_code_copy)
    LinearLayout llOrderCodeCopy;
    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;
    @BindView(R.id.tv_order_state)
    TextView tvOrderState;
    @BindView(R.id.tv_enter)
    TextView tvEnter;
    @BindView(R.id.ll_address)
    LinearLayout llAddress;
    @BindView(R.id.ll_jijian_address)
    LinearLayout llJijianAddress;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.ll_huiji_show_address)
    LinearLayout llHuijiShowAddress;
    @BindView(R.id.tv_add_address)
    TextView tvAddAddress;
    @BindView(R.id.ll_huiji_address)
    LinearLayout llHuijiAddress;


    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("待报价");
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_sold_order);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {

    }

    @Override
    protected void initListener() {

        SoldChangeDialog dialog = new SoldChangeDialog(this);
        dialog.show();

    }


    @OnClick({R.id.tv_express_find, R.id.tv_add_address, R.id.ll_server, R.id.tv_enter})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_express_find:
                break;
            case R.id.tv_add_address: {
                Intent intent = new Intent(this, AddressActivity.class);
                intent.putExtra("isSelect", true);
                startActivityForResult(intent, 221);
            }
            break;
            case R.id.ll_server:
                break;
            case R.id.tv_enter:
//                startActivityForResult(new Intent(this, EdtExpressActivity.class), 222);
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                if (requestCode == 221) {
                    addressModel = (AddressModel) data.getSerializableExtra("model");
                    setAddress();
                } else if (requestCode == 222) {
                    String company = data.getStringExtra("company");
                    String num = data.getStringExtra("num");
                }
            }
        }
    }

    private AddressModel addressModel;

    private void setAddress() {

    }


    int state;


    /**
     * 1.待报价 2.已报价 3.已寄件 4.出售中 5.已完成
     *
     * @param state
     */
    public void setState(int state) {
        this.state = state;
        if (state == 1) {
            getTitleText().setText("待报价");
            llExpress.setVisibility(View.GONE);
            titleViewLine.setVisibility(View.GONE);
            llJijianAddress.setVisibility(View.GONE);
            llHuijiAddress.setVisibility(View.GONE);
            tvEnter.setVisibility(View.GONE);
            tvOrderState.setText("待报价");
        } else if (state == 2) {
            getTitleText().setText("已报价");
            llExpress.setVisibility(View.GONE);
            titleViewLine.setVisibility(View.GONE);
            //填写商品价格
            // ...
            llJijianAddress.setVisibility(View.VISIBLE);
            llHuijiAddress.setVisibility(View.VISIBLE);
            setAddress();
            tvEnter.setVisibility(View.VISIBLE);
            tvEnter.setText("填写寄件物流");
            tvOrderState.setText("已报价");
        } else if (state == 3) {
            getTitleText().setText("已寄件");
            llExpress.setVisibility(View.VISIBLE);
            titleViewLine.setVisibility(View.VISIBLE);
            //填写商品价格
            // ...
            llJijianAddress.setVisibility(View.VISIBLE);
            llHuijiAddress.setVisibility(View.VISIBLE);
            tvEnter.setVisibility(View.GONE);
            tvOrderState.setText("已寄件");
        } else if (state == 4) {
            getTitleText().setText("出售中");
            llExpress.setVisibility(View.GONE);
            titleViewLine.setVisibility(View.GONE);
            //填写商品价格  及状态
            // ...
            llJijianAddress.setVisibility(View.VISIBLE);
            llHuijiAddress.setVisibility(View.VISIBLE);
            setAddress();
            tvEnter.setVisibility(View.GONE);
            tvOrderState.setText("出售中");
        } else if (state == 5) {
            getTitleText().setText("已完成");
            llExpress.setVisibility(View.VISIBLE);
            titleViewLine.setVisibility(View.VISIBLE);
            //填写商品价格  及状态
            // ...
            llJijianAddress.setVisibility(View.VISIBLE);
            llHuijiAddress.setVisibility(View.VISIBLE);
            setAddress();
            tvEnter.setVisibility(View.GONE);
            tvOrderState.setText("已完成");
        }
    }
}
